/**
 * 
 */
var userData = require("UserData");
var wxInterface = require("wxInterface");
cc.Class({
    extends: cc.Component,

    properties: {
        subContextView:cc.WXSubContextView,
        toggleGuoZhi:cc.Toggle,
        toggleNum:cc.Toggle, 
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () { 

    },

    // update (dt) {},
    onEnable(){
        // this.showRank(1);
        this.show();
    },
    showRank(rankIdx){
        // if(rankIdx == 1){
        //     this.toggleGuoZhi.isChecked = true;
        // }else if(rankIdx == 2){
        //     this.toggleNum.isChecked = true;
        // }
        if( cc.sys.browserType != cc.sys.BROWSER_TYPE_WECHAT_GAME){
            return;
        }
        if(rankIdx == 1){
            wx.postMessage({
                "type":  "0", //刷新
                "nickName": userData.instance.nickName,
                "gender":   userData.instance.gender,
                "avatarUrl":userData.instance.avatarUrl,
                "score":userData.instance.histroyScore
            });  
        }else if(rankIdx == 2){
            wx.postMessage({
                "type":  "2", //刷新
                "nickName": userData.instance.nickName,
                "gender":   userData.instance.gender,
                "avatarUrl":userData.instance.avatarUrl,
                "score":userData.instance.histroyScore_2
            });  
        }

        this.subContextView.updateSubContextViewport();
    },
    clickTab(evt, param){
        if(param == 1){
            this.showRank(param);
        }else if(param == 2){
            this.showRank(param);
        }
    },
    clickShareBtn () {
        if(userData.instance.curGameType == 0){
            wxInterface.instance.sendShareMsg("看谁最厉害！来比一比！", 'share.jpg');    
        }else if(userData.instance.curGameType == 1){
            wxInterface.instance.sendShareMsg("看谁最厉害！来比一比！", 'share_1.jpg');
        }
    },
    show(){
        this.node.x = -600;
        this.node.y = 0;
        this.node.active = true;
        var act = cc.moveTo(0.5, cc.v2(0, 0));
        act.easing(cc.easeBackOut());
        var seq = cc.sequence(act, cc.callFunc(function(){
            this.showRank(1);
        }.bind(this)));
        this.node.stopAllActions();
        this.node.runAction(seq);
    },
    clickCloseBtn () {

        var act = cc.moveTo(0.5, cc.v2(600, 0));
        act.easing(cc.easeBackIn());
        var seq = cc.sequence(act, cc.callFunc(function(){
            this.node.active = false;
            // var uiMgr = userData.instance.getUIMgr();
            // var com = uiMgr.getUICom('LoginUI')
            // if(com && com.node.active==true){
            //     com.showBannerAd();
            //     com.showUserInfoBtn();
            //     return;
            // }
        }.bind(this)));
        this.node.stopAllActions();
        this.node.runAction(seq);


        // this.node.active = false;
        // var uiMgr = userData.instance.getUIMgr();
        // var com = uiMgr.getUICom("MainUI");
        // if(com && com.node.active == true){
        //     com.clickRetryBtn();
        //     return;
        // }
        // com = uiMgr.getUICom("MainUI_2");
        // if(com && com.node.active == true){
        //     com.clickRetryBtn();
        //     return;
        // }

        // var obj = cc.find("Canvas/LoginUI");
        // obj.active = true;
        // var com = obj.getComponent("LoginUI");
        // com.setOrigin();
    },
});
